import com.yeung.ssm.bean.BookExample;
import com.yeung.ssm.dao.BookMapper;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

public class IbatisTest extends BaseTest {

    /*private static SqlSessionFactory sessionFactory;
    private static SqlSession session;*/
    @Autowired
    private static SqlSession session;
/*

    static {
        InputStream resourceAsStream = null;
        try {
            //拿到配置文件的数据流
            resourceAsStream = Resources.getResourceAsStream("mybatis-config.xml");
        } catch (IOException e) {
            System.out.println("找不到这个配置文件");
        }
        //创建 sessionFactory
        sessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
    }
*/

/*    public static SqlSession getSession() {
        if (session == null)
            session = sessionFactory.openSession();
        return session;
    }*/


    @Test
    public void Test() throws Exception {
        BookMapper mapper = session.getMapper(BookMapper.class);
        BookExample bookExample = new BookExample();
        BookExample.Criteria criteria = bookExample.createCriteria();
        criteria.andIdEqualTo(2);
        mapper.selectByExample(bookExample);
    }
}



